import random
from typing import Tuple


def bubble_sort(arr):
    if not arr or len(arr) < 2:
        return
    n = len(arr)
    for _ in range(0, n):
        for i in range(n - 1, 0, -1):
            if arr[i] < arr[i - 1]:
                arr[i], arr[i - 1] = arr[i - 1], arr[i]


def test(n: int, ranges: Tuple[int, int], t: int):
    '''
    测试函数
    :param n: 测试数组长度
    :param maximum: 生成数组元素的大小范围
    :param t: 测试轮数
    '''
    for _ in range(t):
        arr1 = [random.randint(ranges[0], ranges[1]) for _ in range(n)]
        arr2 = arr1[:]
        arr3 = arr1[:]
        bubble_sort(arr2)
        arr3.sort()
        passed = arr2 == arr3
        if not passed:
            print('error!!!')
            print(arr1)
            print(arr2)
            print(arr3)


if __name__ == '__main__':
    test(1000, (-1000, 1000), 100)
    print("测试结束")
